<?php

class CartController extends Zend_Controller_Action
{

    public function init()
    {
        
    }

    public function indexAction()
    {
        
    }
    public function detailAction(){
    	$this->view->username=Model_Account::currentUser();   	
    	$delMapper=new Model_DeliveryMapper();
    	$delivery=$delMapper->getDeliveryOfLocation(1);
    	$this->view->del=$delivery;
    }
    
    
   public function banklistAction(){
   	
   }
 	public function paymentAction(){
 		$form = new Form_Payment();
 		$this->view->form = $form;
 	}
 	public function authAction(){
 	
 		$this->_helper->layout()->disableLayout();
 		$this->_helper->viewRenderer->setNoRender(true);
 	
 		$request 	= $this->getRequest();
 		$registry 	= Zend_Registry::getInstance();
 		$auth		= Zend_Auth::getInstance();
 	
 		$DB = $registry['my_db'];
 	
 		$authAdapter = new Zend_Auth_Adapter_DbTable($DB);
 		$authAdapter->setTableName('order')
 		->setIdentityColumn('Name')
 		->setCredentialColumn('CardNumber');
 	
 		// Set the input credential values
 		$namecard = $request->getParam('name');
 		$numcard = $request->getParam('numcard');
 	
 		$authAdapter->setIdentity($namecard);
 		$authAdapter->setCredential($numcard);
 	
 		// Perform the authentication query, saving the result
 		$result = $auth->authenticate($authAdapter);
 	
 		if($result->isValid()){
 			$data = $authAdapter->getResultRowObject(null,'password');
 			$auth->getStorage()->write($data->Username);
 			// 			$this->_redirect('/index/index');
 			echo "success";
 		}else{
 			//$this->_redirect('/account/login');
 			echo "failed";
 		}
 	
 	}
    public function checkoutAction(){
    	$cart=new Model_CartHelper();
    	$result=$cart->WriteToDatabase();
    	$this->view->result=$result;
    }

}

